﻿
using System;
using MediaBrowserSL.RIA.ViewModels;
using MediaBrowserSL.RIA.Views;

namespace MediaBrowserSL.RIA.MvvmUtils.UI
{
    /// <summary>
    /// Settings Windows  
    /// </summary>
    public class WindowSettingsVisualizer : IWindowSettingsVisualizer
    {
        private ChildWindowSettings dlg;
        private Action<object> closeCallback;

        public WindowSettingsVisualizer()
        {
            dlg = new ChildWindowSettings();
            dlg.Closed += dlg_Closed;
            EventHandler handler = null;
            handler = delegate
            {
                ((ViewModelBase)dlg.DataContext).RequestClose -= handler;
                dlg.Close();
            };
            ((ViewModelBase)dlg.DataContext).RequestClose += handler;
        }

        void dlg_Closed(object sender, EventArgs e)
        {
            closeCallback(sender);
        }

        /// <summary>
        /// Show Settings Window 
        /// </summary>
        public void Show(Action<object> closeCallback)
        {
            this.closeCallback = closeCallback;
            dlg.Show();
        }
    }
}
